﻿using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;

namespace AutoChange
{
    class Win32API
    {
        public const int SRCCOPY = 0x00CC0020;
        public const int WM_KEYDOWN = 0x0100;
        public const int WM_KEYUP = 0x0101;

        [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
        public static extern IntPtr GetForegroundWindow();

        [DllImport("user32.dll", EntryPoint = "SendMessage")]
        public static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);

        [DllImport("user32.dll")]
        public static extern bool PrintWindow(
          IntPtr hwnd,               // Window to copy,Handle to the window that will be copied. 
          IntPtr hdcBlt,             // HDC to print into,Handle to the device context. 
          UInt32 nFlags              // Optional flags,Specifies the drawing options. It can be one of the following values. 
          );

        [DllImport("user32.dll", EntryPoint = "WindowFromPoint")]//指定坐标处窗体句柄       
        public static extern IntPtr WindowFromPoint(int xPoint, int yPoint);

        [DllImport("user32.dll")]
        public static extern IntPtr GetWindowDC(
           IntPtr hwnd
           );

        [System.Runtime.InteropServices.DllImport("User32.dll")]
        public static extern IntPtr GetDC(IntPtr Hwnd); //其在MSDN中原型为HDC GetDC

        [DllImport("gdi32.dll")]
        public static extern IntPtr CreateCompatibleBitmap(
           IntPtr hdc,        // handle to DC
           int nWidth,     // width of bitmap, in pixels
           int nHeight     // height of bitmap, in pixels
           );

        [DllImport("gdi32.dll")]
        public static extern IntPtr SelectObject(
           IntPtr hdc,          // handle to DC
           IntPtr hgdiobj   // handle to object
           );

        [DllImport("gdi32.dll")]
        public static extern bool DeleteDC(IntPtr hDC);

        [DllImport("gdi32.dll")]
        public static extern IntPtr CreateCompatibleDC(
          IntPtr hdc // handle to DC
          );

        [DllImport("user32.dll")]
        public static extern IntPtr GetWindowRect(IntPtr hWnd, out Rect rect);

        [DllImport("gdi32.dll")]
        public static extern bool BitBlt(IntPtr hObject, int nXDest, int nYDest,
            int nWidth, int nHeight, IntPtr hObjectSource,
            int nXSrc, int nYSrc, int dwRop);

        [DllImport("user32.dll")]
        public static extern IntPtr ReleaseDC(IntPtr hWnd, IntPtr hDC);

        [DllImport("gdi32.dll")]
        public static extern bool DeleteObject(IntPtr hObject);


        [DllImport("user32.dll")]
        public static extern int GetWindowTextLength(IntPtr hWnd);

        [DllImport("User32.dll", CharSet = CharSet.Auto)]
        public static extern int GetWindowText(IntPtr hWnd, StringBuilder text, int nMaxCount);

        public struct Rect
        {
            public int Left;
            public int Top;
            public int Right;
            public int Bottom;
        }
    }
}
